package com.study.security;

import com.study.utils.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 密码处理的工具类
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {
    DefaultPasswordEncoder(){
        this(-1);
    }
    DefaultPasswordEncoder(int strength){

    }
    //对字符串或者数据进行MD5加密
    @Override
    public String encode(CharSequence charSequence) {
        return MD5.encrypt(charSequence.toString());
    }
    //对密码进行比对第一个参数是要加密的密码 第二个参数传入密码加密后的
    @Override
    public boolean matches(CharSequence charSequence, String encodePassword) {
        return encodePassword.equals(MD5.encrypt(charSequence.toString()));
    }
}
